﻿using System;
using System.Runtime.Serialization;
using Hopscotch.Domain.Common;
using Hopscotch.Domain.Common.StateTracking;

namespace Hopscotch.Test.Presentation
{
    public class TestEntity : DomainBase<int>
    {
        private int _id;
        private string _accountId;

        public virtual void Merge(TestEntity copy)
        {
            base.Merge(copy);

            _accountId = copy.AccountId;
        }

        [DataMember]
        public override int Id
        {
            get { return _id; }
            set
            {
                if (_id != value)
                {
                    if (ChangeTracker.ChangeTrackingEnabled && ChangeTracker.State != ObjectState.Added)
                    {
                        throw new InvalidOperationException("The property 'Id' is part of the object's key and cannot be changed. Changes to key properties can only be made when the object is not being tracked or is in the Added state.");
                    }
                    _id = value;
                    OnPropertyChanged("Id");
                }
            }
        }

        [DataMember]
        public string AccountId
        {
            get { return _accountId; }
            set
            {
                if (_accountId != value)
                {
                    ChangeTracker.RecordOriginalValue("AccountId", _accountId);
                    _accountId = value;
                    OnPropertyChanged("AccountId");
                }
            }
        }

        public override object Clone()
        {
            throw new NotImplementedException();
        }

        
    }
}
